﻿using PLC.Core.Entities;
using PLC.Interface.ActualDatas;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using YWM.Application;
using YWM.Application.Linq.Extensions;

namespace PLC.Application.ActualDatas.Services
{
    internal class ActualDataService : AsyncCrudService<ActualData, ActualDataResultDto, long, ActualDataResultRequestDto, ActualDataDto>, IActualDataService
    {
        protected override IQueryable<ActualData> CreateFilteredQuery(ActualDataResultRequestDto input)
        {
            IQueryable<ActualData> queryable = base.CreateFilteredQuery(input)
                .WhereIf(input.StartTime != null, ad => ad.CreationTime >= input.StartTime)
                .WhereIf(input.EndTime != null, ad => ad.CreationTime <= input.EndTime);
            return queryable;
        }

        public async Task Create(List<ActualDataDto> input)
        {
            foreach (ActualDataDto item in input)
            {
                await Create(item);
            }
        }
    }
}
